package com.mogujie.tt.ui.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.mogujie.tt.DB.sp.RegisterSp;
import com.mogujie.tt.R;
import com.mogujie.tt.ui.base.QZBaseActivity;
import com.mogujie.tt.ui.base.TTBaseActivity;
import com.mogujie.tt.utils.SubmitUserDetailsTask;

/**
 * Created by user on 2015/10/29.
 */
public class UpdateNickActivity extends QZBaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater.from(this).inflate(R.layout.tt_activity_update_nick, topContentView);
        showTopInformation("修改昵称");

        final String nick= RegisterSp.instance().getSpDetailedInfo().getDetailedNickName();

        final EditText et_nick= (EditText) this.findViewById(R.id.et_nick);
        et_nick.setText(nick);
        TextView tv_save= (TextView) this.findViewById(R.id.tv_save);
        tv_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String newNick = et_nick.getText().toString().trim();
                if (nick.equals(newNick) || newNick.equals("") || newNick.equals("0")) {
                    return;
                }
                RegisterSp.instance().setdetailedNickNameStrConfig(newNick);
                new SubmitUserDetailsTask(UpdateNickActivity.this).execute();//提交用户详细信息
                Toast.makeText(UpdateNickActivity.this,"更新昵称成功",Toast.LENGTH_SHORT).show();
            }
        });

    }

    /**
     * 显示顶部信息
     */
    private void showTopInformation(String test){
        if(test == null){
            return;
        }
        setTopBarDisplay();
        setCenterText(test);
    }


    public void onClickExit(View view){
        finish();
    }

}
